app.controller("z-approval-c", [ '$scope','$rootScope','$z-http','$sce','z-approval-s','z-attendance-s','z-edit-menu-s','$filter',
		function($scope,$rootScope,$zhttp,$sce,Service,AttendanceService,MenuService,$filter) {
		$scope.viewModel = {};
		$scope.viewModel.perPage = "10";
		$scope.viewModel.rowCount = "1";		
		$scope.viewModel.requestType=null;
		$scope.viewModel.requestRole=null;

		//编辑
		$scope.editModel = {};
		$scope.editModel.approval={};
		$scope.editModel.title="";
		$scope.editModel.requestTypeData=[];
		$scope.editModel.requestRoleData=[];
		$scope.editModel.oneApprovalRoleData=[];
		$scope.editModel.twoApprovalRoleData=[];
		$scope.editModel.threeApprovalData=[];
		$scope.editModel.fourApprovalRoleData=[];
		$scope.editModel.fiveApprovalRoleData=[];
		
		//查询页面名称
		MenuService.getMenuByUrl({url:'approval'},
		function(data){	
			$scope.viewModel.menuList=data;
		},function(error) {});
		
		//选中事件
		$scope.editModel.selectBindData=function(value,sep){
			if(sep==1){
				AttendanceService.getDictionaryListBydicCls({
					dicCls:"9",
					dicCd:value
				},
				function(data){
					$scope.editModel.oneApprovalRoleData= data;
					$scope.editModel.approval.oneApprovalRole=null;
					$scope.editModel.approval.twoApprovalRole=null;
					$scope.editModel.approval.threeApprovalRole=null;
					$scope.editModel.approval.fourApprovalRole=null;
					$scope.editModel.approval.fiveApprovalRole=null;
					$scope.editModel.twoApprovalRoleData=[];
					$scope.editModel.threeApprovalData=[];
					$scope.editModel.fourApprovalRoleData=[];
					$scope.editModel.fiveApprovalRoleData=[];
				},function(error) {
							
				});
			}else if(sep==2){
				AttendanceService.getDictionaryListBydicCls({
					dicCls:"9",
					dicCd:value
				},
				function(data){
					$scope.editModel.twoApprovalRoleData= data;
					$scope.editModel.approval.threeApprovalRole=null;
					$scope.editModel.threeApprovalData=[];
					$scope.editModel.approval.fourApprovalRole=null;
					$scope.editModel.fourApprovalRoleData=[];
					$scope.editModel.approval.fiveApprovalRole=null;
					$scope.editModel.fiveApprovalRoleData=[];
				},function(error) {
							
				});
			}else if(sep==3){
				AttendanceService.getDictionaryListBydicCls({
					dicCls:"9",
					dicCd:value
				},
				function(data){
					$scope.editModel.threeApprovalData= data;
					$scope.editModel.approval.fourApprovalRole=null;
					$scope.editModel.fourApprovalRoleData=[];
					$scope.editModel.approval.fiveApprovalRole=null;
					$scope.editModel.fiveApprovalRoleData=[];
				},function(error) {
							
				});
			}else if(sep==4){
				AttendanceService.getDictionaryListBydicCls({
					dicCls:"9",
					dicCd:value
				},
				function(data){
					$scope.editModel.fourApprovalRoleData= data;
					$scope.editModel.approval.fiveApprovalRole=null;
					$scope.editModel.fiveApprovalRoleData=[];
				},function(error) {
							
				});
			}else if(sep==5){
				AttendanceService.getDictionaryListBydicCls({
					dicCls:"9",
					dicCd:value
				},
				function(data){
					$scope.editModel.fiveApprovalRoleData= data;
				},function(error) {
							
				});
			}
		};
		
		//加载考勤状态数据
		$scope.viewModel.bindSelectData = function(){
			AttendanceService.getDictionaryListBydicCls({
				dicCls:"8"
			},
			function(data){
				$scope.viewModel.requestTypeData = data;
				$scope.editModel.requestTypeData = data;
			},function(error) {
						
			});
			
			AttendanceService.getDictionaryListBydicCls({
				dicCls:"9"
			},
			function(data){
				$scope.viewModel.requestRoleData= data;
				$scope.editModel.requestRoleData= data;
			},function(error) {
						
			});
		};
		$scope.viewModel.bindSelectData();
		
		//加载
		$scope.viewModel.load=function(){
			$scope.viewModel.show=true;
		};
		
		//关闭加载
		$scope.viewModel.unLoad=function(){
			$scope.viewModel.show=false;
			$scope.editModel.approval={};
		};
		
		//新增
		$scope.viewModel.add = function(approval){
			$scope.editModel.title="新增审批规则";
			$scope.editModel.type = true;
			$scope.editModel.approval={};
			$scope.editModel.oneApprovalRoleData=[];
			$scope.editModel.twoApprovalRoleData=[];
			$scope.editModel.threeApprovalData=[];
			$scope.editModel.fourApprovalRoleData=[];
			$scope.editModel.fiveApprovalRoleData=[];
			//验证不能为空
			$scope.editForm.requestType.$dirty=false;
			$scope.editForm.requestRole.$dirty=false;
			$scope.editForm.fromDays.$dirty=false;
			$scope.editForm.oneApprovalRole.$dirty=false;
			$scope.viewModel.load();
		};
		
		//修正
		$scope.viewModel.update=function(approval){
			$scope.editModel.title="修改审批规则";
			$scope.editModel.type = false;
			$scope.editModel.oneApprovalRoleData=[];
			$scope.editModel.twoApprovalRoleData=[];
			$scope.editModel.threeApprovalData=[];
			$scope.editModel.fourApprovalRoleData=[];
			$scope.editModel.fiveApprovalRoleData=[];
			$scope.editModel.approval=angular.copy(approval);
			$scope.viewModel.load();
		};
		
		//加载数据
		$scope.viewModel.bindData = function(){
			//$scope.viewModel.isLoading=true;
			/*//获取基本信息
			Service.getAttendanceList({
				pageNo:$scope.viewModel.rowCount,
				pageCount:$scope.viewModel.perPage,
				attendanceDateStart:$scope.viewModel.attendanceStratDate,
				attendanceDateEnd:$scope.viewModel.attendanceEndDate,
				attendanceState:$scope.viewModel.attendanceState
			},
			function(data){
				$scope.viewModel.dataList = data.attendanceBeanList;
				$scope.viewModel.totalData = data.pageTotal;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
			});*/
		};
		$scope.viewModel.bindData();
	
		//验证
		$scope.viewModel.requiredForm= function() {
            if (!$scope.editForm.$valid) {
            	if(!$scope.editForm.requestType.$dirty){
            		$scope.editForm.requestType.$dirty=true;
            	}
            	if(!$scope.editForm.requestRole.$dirty){
            		$scope.editForm.requestRole.$dirty=true;
            	}
            	if(!$scope.editForm.fromDays.$dirty){
            		$scope.editForm.fromDays.$dirty=true;
            	}
            	if(!$scope.editForm.oneApprovalRole.$dirty){
            		$scope.editForm.oneApprovalRole.$dirty=true;
            	}
                return true;
            }else{
            	return false;
            }
        };
		
		//保存
		$scope.viewModel.save = function(){
			if($scope.viewModel.requiredForm()){
				return;
			}
			/*$scope.viewModel.isLoading = true;
			Service.saveRetroactive($scope.editModel.retroactive,
				function(data){
					$scope.viewModel.unLoad();
					$scope.viewModel.bindData();
					$rootScope.alertInfo("补签申请提交成功。");
					$scope.viewModel.isLoading = false;
				},function(error) {
					$rootScope.alertError(error.fault.message);
					$scope.viewModel.isLoading = false;
				});*/
		};
} ]);